/**************************************************************************
 * Copyright (C) 2012 Tyler Robertson
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **************************************************************************/

#include "Arduino.h"
#include "SPI/SerialPeripheralInterface.h"



void SetLEDValue( LEDSet led, unsigned char value )
{
	spi_select_slave( SS );
	spi_write_byte( (unsigned char)led );
	spi_write_byte( value );
	spi_deselect_slave( SS );
}

void setup()
{
	Serial.begin( 9600 );
	Serial.println( "Initialized" );
	
	spi_initialize();
}

void loop()
{
	LEDSet led = (LEDSet)3;
	
	SetLEDValue( led, 0 );

	Serial.print( "value: " );
	Serial.println( 0, DEC );
	delay( 5000 );
		
	SetLEDValue( led, 128 );
	Serial.print( "value: " );
	Serial.println( 128, DEC );
	delay( 5000 );

	SetLEDValue( led, 255 );
	Serial.print( "value: " );
	Serial.println( 255, DEC );
	delay( 5000 );

	
//	for( char i=0; i<255; i++ )
//	{
//		digital_pot_set( 3, i );
//		Serial.print( "value: " );
//		Serial.println( i, DEC );
//		delay( 250 );
//	}
}